import Vue from 'vue'
import VueRouter from 'vue-router'
// 静态引入路由页面（不推荐这个，推荐动态引入）
// import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

/**
 * 1. 一级路由
 * 2. 二级路由 （重定向）
 * 3. 三级路由
 *
 */

const routes = [
  // 1. 路由重定向，为了让用户，第一次进入页面的时候，让用户能看到你想让他看到的页面
  {
    path: '/',
    redirect: '/layout',
  },
  {
    path: '/login',
    name: 'Login',
    meta: {
      title: '登陆',
    },
    component: () => import(/* webpackChunkName: "login" */ '../views/Login.vue'),
  },
  // 动态路由
  {
    path: '/detail/:detailId',
    name: 'Detail',
    component: () => import('../views/detail/index.vue'),
  },
  {
    path: '/layout',
    name: 'Layout',
    component: () => import(/* webpackChunkName: "layout" */ '../layouts/index.vue'),
    // 二级重定向
    redirect: '/layout/home',
    children: [
      {
        path: 'home',
        name: 'home',
        component: () => import(/* webpackChunkName: "about" */ '../views/home/HomeView.vue'),
        // 三级重定向
        redirect: '/layout/home/homeA',
        children: [
          {
            path: 'homeA',
            name: 'HomeA',
            meta: {
              title: 'HomeA',
            },
            component: () => import('../views/home/home-page/HomeA.vue'),
          },
          {
            path: 'homeB',
            name: 'HomeB',
            meta: {
              title: 'HomeB',
            },
            component: () => import('../views/home/home-page/HomeB.vue'),
          },
        ],
      },
      {
        path: 'about',
        name: 'about',
        // 导航元信息
        meta: {
          title: '关于页面',
        },
        // 动态引入（懒加载引入）动态分割技术
        // webpack chunk 块 name 名字
        component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue'),
      },
    ],
  },

  // 2. 如果用户输入页面路由信息，找不到的话，提示一个页面，让用户继续找
  {
    path: '*',
    component: () => import(/* webpackChunkName: "404" */ '../views/NotFound.vue'),
  },
]

const router = new VueRouter({
  mode: 'history', // 路由模式 hash
  base: process.env.BASE_URL,
  routes,
})

export default router
